# -*- coding: utf-8 -*-
"""
Created on Fri Sep  9 12:57:19 2016

@author: zhiqiang
solved = False
pentagonalist = set()
i = 0
while solved != True:
    i += 1
    pnum = int(i*(3*i-1)/2)
    pentagonalist.add(pnum)
    for num in pentagonalist:
        if pnum - num in pentagonalist and pnum - num*2 in pentagonalist:
            print("the answer is:", abs(num - (pnum - num)))
            solved = True"""
#eulerproject44
list1 = [1, 5, 12, 22, 35, 51, 70, 92, 117, 145]
i = 0
max_index = 10
while True:
    j = i + 1
    is_break = False
    while list1[i]+list1[j]>list1[-1]:
        max_index += 1
        list1.append(max_index*(3*max_index))
    while list1[i]+list1[j]>=list1[j+1]:
        #如果测试用数比下一个数大，那么继续寻找
        if (list1[i]+list1[j] in list1) and (list1[j]-list1[i] in list1):
            #如果遇到相等的情况
            #计算一下二者的差是否在数列中
           print(list1[j]-list1[i])
           is_break = True
           break
        else:
           j = j+1
           while list1[i]+list1[j]>list1[-1]:
               max_index += 1
               list1.append(max_index*(3*max_index-1)//2)
    if is_break:
        break
    else:
        i = i+1   